from manim import *


class graphAreaPlot(Scene):
    def construct(self):
        ax = Axes(
            x_range=[0, 5],
            y_range=[0, 5],
            x_axis_config={
                # "numbers_to_include": [0, 0.5, 1, 2, 3, 4, 5],
                "include_numbers": True,
            },
        )
        label = ax.get_axis_labels()
        curve_1 = ax.plot(lambda x: -(x**2) + 4 * x, x_range=[0, 4], color=BLUE_C)
        curve_2 = ax.plot(lambda x: 0.8 * x**2 - 3 * x + 4, x_range=[0, 4], color=GREEN_B)
  
        # 曲线curve_1 与 x轴 围成区域 --> 黎曼矩形
        area_1 = ax.get_riemann_rectangles(curve_1, x_range=[0.5, 1.0], dx=0.02, color=BLUE_C, fill_opacity=0.5)
        # 曲线curve_1 与 curve_2 围成区域
        area_2 = ax.get_area(curve_2,[2, 3], bounded_graph=curve_1, color=GREY, fill_opacity=0.5)

        # self.add(ax, label, curve_1, curve_2, area_1, area_2)
        line_x_2 = ax.get_vertical_line(ax.i2gp(2, curve_1))
        line_x_3 = ax.get_vertical_line(ax.i2gp(3, curve_1))
        self.add(ax, label, curve_1, curve_2, area_1, area_2, line_x_2, line_x_3)
